import api from './api'

export const crudOptions = vm => {
  return {
    indexRow: {
      title: '序号',
      align: 'center'
    },
    options: {height: '100%'},
    columns: [
      {
        title: '献血志愿者',
        key: 'volunteerName',
        align: 'center',
        type: 'select',
        search: {
          width: 233,
          key: 'volunteerName',
          disabled: false,
          component: {
            name: 'dict-select',
            placeholder: '请选择献血的志愿者，若无则需添加该志愿者'
          }
        },
        form: {
          rules: [
            {required: true, trigger: 'blur', message: '请选择献血的志愿者'}
          ],
          component: {
            placeholder: '请选择献血的志愿者，若无则需添加该志愿者',
            props: {
              filterable: true,
              multiple: false,
              clearable: true
            }
          }
        },
        dict: {
          // url: '/api/volunteer/page',
          value: '_id',
          label: 'name',
          isTree: false,
          getData: async (url, dict, {form, component}) => {
            const {data} = await api.getVolunteerList()
            return data.data
          }
        },
        valueBuilder(row, key) {
        },
        valueResolve(row, key) {
          row.volunteerId = row.volunteerName
        }
      },
      {
        title: '血型',
        key: 'bloodType',
        align: 'center',
        dict: {
          isTree: false,
          data: [
            {
              value: 'A',
              label: 'A'
            },
            {
              value: 'B',
              label: 'B'
            },
            {
              value: 'AB',
              label: 'AB'
            },
            {
              value: 'O',
              label: 'O'
            }
          ]
        },
        search: {
          disabled: true,
          component: {
            name: 'dict-select',
            props: {
              filterable: true,
              multiple: false,
              clearable: true
            }
          }
        },
        form: {
          disabled: true
        }
      },
      {
        title: '血量(mm)',
        key: 'bloodVolume',
        align: 'center',
        form: {
          rules: [
            {required: true, trigger: 'blur', message: '请输入献血量'},
            {pattern: /^\+?[1-9][0-9]*$/, trigger: 'blur', message: '请输入数字'}
          ]
        }
      },
      {
        title: '采血者',
        key: 'drawer',
        align: 'center',
        form: {
          rules: [
            {required: true, trigger: 'blur', message: '请输入采血者'},
            {max: 10, trigger: 'blur', message: '采血者姓名限10个字符串内'}
          ]
        }
      },
      {
        title: '采血日期',
        key: 'drawDate',
        align: 'center',
        sortable: true,
        type: 'datetime',
        width: 200,
        form: {
          disabled: false,
          component: {
            placeholder: '请选择采血时间，不选择则默认当前时间',
            style: {
              width: '350px'
            }
          }
        }
      },
      {
        title: '有效期至',
        key: 'expireDate',
        align: 'center',
        width: 200,
        form: {
          disabled: true
        }
      },
      {
        title: '有效天数',
        key: 'shelfLife',
        align: 'center',
        form: {
          disabled: false,
          rules: [
            {required: true, trigger: 'blur', message: '请输入血液有效天数'},
            {pattern: /^\+?[1-9][0-9]*$/, trigger: 'blur', message: '请输入整数'}
          ]
        }
      },
      {
        title: '是否合格',
        key: 'isQualified',
        align: 'center',
        type: 'select',
        search: {
          disabled: false,
          show: false
        },
        dict: {
          data: [
            {value: 1, label: '合格'},
            {value: 0, label: '不合格'}
          ]
        },
        form: {
          rules: [
            {required: true, trigger: 'blur', message: '请选择血液是否合格'}
          ],
          component: {
            name: 'dict-select',
            props: {
              filterable: true,
              multiple: false,
              clearable: true
            }
          }
        }
      },
      {
        title: '是否过期',
        key: 'isOutdated',
        align: 'center',
        type: 'select',
        dict: {
          data: [
            {value: 1, label: '已过期'},
            {value: 0, label: '未过期'}
          ]
        },
        form: {
          disabled: true
        }
      },
      {
        title: '是否入库',
        key: 'isRepos',
        align: 'center',
        type: 'select',
        form: {
          disabled: true
        },
        dict: {
          data: [
            {value: 0, label: '未入库'},
            {value: 1, label: '已入库'},
            {value: 2, label: '已出库'}
          ]
        },
      },
      {
        title: '备注',
        key: 'remark',
        align: 'center',
        formatter(row) {
          return row.remark ? row.remark : '无'
        }
      }
    ],
    rowHandle: {
      view: false,
      align: 'center',
      custom: [
        {
          width: 350,
          thin: false,
          text: '仓库',
          // type: 'primary',
          icon: 'el-icon-edit',
          size: 'small',
          show: true,
          disabled: false,
          order: 1,
          emit: 'rk'
        }
      ]
    }
  }
}
